    program sort_fees
      character*120 var(24,450000),vrs
      dimension ic(24),iastid(24,450000),idate(24,450000)
!      open(unit=10,file='e:\FIS\fees_200501_200503.txt')
!      open(unit=99,file='e:\FIS\sorted_fees_200501_200503.txt')
      open(unit=10,file='e:\FIS\fees_201401_201403_ret_rep.txt')
      open(unit=99,file='e:\FIS\sorted_fees_201401_201403_rep.txt')
      ic=0
1     read(10,1000,end=10)ias,idt,vrs
1000  format(1x,i8,1x,i8,a120)      
!      n=24
!      if(ias.lt.200000) n=1
!      if(ias.ge.200000.and.ias.lt.300000) n=2
!      if(ias.ge.300000.and.ias.lt.400000) n=3
!      if(ias.ge.400000.and.ias.lt.500000) n=4
!      if(ias.ge.500000.and.ias.lt.600000) n=5
!      if(ias.ge.600000.and.ias.lt.700000) n=6
!      if(ias.ge.700000.and.ias.lt.800000) n=7
!      if(ias.ge.800000.and.ias.lt.900000) n=8
!      if(ias.ge.900000.and.ias.lt.1000000) n=9
!      if(ias.ge.1000000.and.ias.lt.10100000) n=10
!      if(ias.ge.10100000.and.ias.lt.10150000) n=11
!      if(ias.ge.10150000.and.ias.lt.10200000) n=12
!      if(ias.ge.10200000.and.ias.lt.10250000) n=13
!      if(ias.ge.10250000.and.ias.lt.10300000) n=14
!      if(ias.ge.10300000.and.ias.lt.10310000) n=15
!      if(ias.ge.10310000.and.ias.lt.10320000) n=16
!      if(ias.ge.10320000.and.ias.lt.10330000) n=17
!      if(ias.ge.10330000.and.ias.lt.10350000) n=18
!      if(ias.ge.10350000.and.ias.lt.10370000) n=19
!      if(ias.ge.10370000.and.ias.lt.10380000) n=20
!      if(ias.ge.10380000.and.ias.lt.10390000) n=21
!      if(ias.ge.10390000.and.ias.lt.10400000) n=22
!      if(ias.ge.10400000.and.ias.lt.10410000) n=23
!      n=21
!!      if(ias.lt.110000) n=1
!      if(ias.ge.110000.and.ias.lt.160000) n=2
!      if(ias.ge.160000.and.ias.lt.230000) n=3
!      if(ias.ge.230000.and.ias.lt.250000) n=4
!      if(ias.ge.250000.and.ias.lt.420000) n=5
!      if(ias.ge.420000.and.ias.lt.490000) n=6
!      if(ias.ge.490000.and.ias.lt.515000) n=7
!      if(ias.ge.515000.and.ias.lt.525000) n=8
!      if(ias.ge.525000.and.ias.lt.570000) n=9
!      if(ias.ge.570000.and.ias.lt.590000) n=10
!      if(ias.ge.590000.and.ias.lt.660000) n=11
!      if(ias.ge.660000.and.ias.lt.680000) n=12
!      if(ias.ge.680000.and.ias.lt.800000) n=13
!      if(ias.ge.800000.and.ias.lt.880000) n=14
!      if(ias.ge.880000.and.ias.lt.1000000) n=15
!      if(ias.ge.1000000.and.ias.lt.10060000) n=16
       n=21
      if(ias.lt.107000) n=1
      if(ias.ge.107000.and.ias.lt.120000) n=2
      if(ias.ge.120000.and.ias.lt.160000) n=3
      if(ias.ge.160000.and.ias.lt.180000) n=4
      if(ias.ge.180000.and.ias.lt.203000) n=5
      if(ias.ge.203000.and.ias.lt.218000) n=6
      if(ias.ge.218000.and.ias.lt.280000) n=7
      if(ias.ge.280000.and.ias.lt.495000) n=8
      if(ias.ge.495000.and.ias.lt.510000) n=9
      if(ias.ge.510000.and.ias.lt.520000) n=10
      if(ias.ge.520000.and.ias.lt.525000) n=11
      if(ias.ge.525000.and.ias.lt.590000) n=12
      if(ias.gt.590000) n=13
      ic(n)=ic(n)+1
      iastid(n,ic(n))=ias
      idate(n,ic(n))=idt
      var(n,ic(n))=vrs
      go to 1
10    continue    
      write(6,6000)(ic(n),n=1,21)
6000  format(21(1x,i6))  
      do 100 i=1,9
          write(6,6002)i
6002  format(1x,i6)          
      icnt=ic(i)
      icntm=ic(i)-1
      do 50 ii=1,icntm
          ip=ii+1
          do 40 jj=ip,icnt
              if(iastid(i,ii).lt.iastid(i,jj)) go to 40
              if(iastid(i,ii).eq.iastid(i,jj).and.idate(i,ii).lt.idate(i,jj)) go to 40
             it1=iastid(i,ii)
             it2=idate(i,ii)
             vrs=var(i,ii)
              iastid(i,ii)=iastid(i,jj)
              idate(i,ii)=idate(i,jj)
              var(i,ii)=var(i,jj)
              iastid(i,jj)=it1
              idate(i,jj)=it2
              var(i,jj)=vrs
40        continue
50    continue
      do 60 ii=1,icnt
60        write(99,1000)iastid(i,ii),idate(i,ii),var(i,ii)
100   continue             
      stop

    end program sort_fees
